package com.ruoyi.web.controller.match;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.match.domain.MatchAttachments;
import com.ruoyi.match.service.IMatchAttachmentsService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 附件Controller
 * 
 * @author 星野漫游
 * @date 2024-06-02
 */
@Controller
@RequestMapping("/match/attachment")
public class MatchAttachmentsController extends BaseController
{
    private String prefix = "match/attachment";

    @Autowired
    private IMatchAttachmentsService matchAttachmentsService;

    @RequiresPermissions("match:attachment:view")
    @GetMapping()
    public String attachment()
    {
        return prefix + "/attachment";
    }

    /**
     * 查询附件列表
     */
    @RequiresPermissions("match:attachment:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(MatchAttachments matchAttachments)
    {
        startPage();
        List<MatchAttachments> list = matchAttachmentsService.selectMatchAttachmentsList(matchAttachments);
        return getDataTable(list);
    }

    /**
     * 导出附件列表
     */
    @RequiresPermissions("match:attachment:export")
    @Log(title = "附件", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(MatchAttachments matchAttachments)
    {
        List<MatchAttachments> list = matchAttachmentsService.selectMatchAttachmentsList(matchAttachments);
        ExcelUtil<MatchAttachments> util = new ExcelUtil<MatchAttachments>(MatchAttachments.class);
        return util.exportExcel(list, "附件数据");
    }

    /**
     * 新增附件
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存附件
     */
    @RequiresPermissions("match:attachment:add")
    @Log(title = "附件", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(MatchAttachments matchAttachments)
    {
        return toAjax(matchAttachmentsService.insertMatchAttachments(matchAttachments));
    }

    /**
     * 修改附件
     */
    @RequiresPermissions("match:attachment:edit")
    @GetMapping("/edit/{attachmentId}")
    public String edit(@PathVariable("attachmentId") Long attachmentId, ModelMap mmap)
    {
        MatchAttachments matchAttachments = matchAttachmentsService.selectMatchAttachmentsByAttachmentId(attachmentId);
        mmap.put("matchAttachments", matchAttachments);
        return prefix + "/edit";
    }

    /**
     * 修改保存附件
     */
    @RequiresPermissions("match:attachment:edit")
    @Log(title = "附件", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(MatchAttachments matchAttachments)
    {
        return toAjax(matchAttachmentsService.updateMatchAttachments(matchAttachments));
    }

    /**
     * 删除附件
     */
    @RequiresPermissions("match:attachment:remove")
    @Log(title = "附件", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(matchAttachmentsService.deleteMatchAttachmentsByAttachmentIds(ids));
    }
}
